﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Core.Domain;
using Library.Extensions.Expressions;

namespace Core.Queries
{
    public class LogQuery : Query<Log>
    {
        public Guid? Ticket { get; set; }
        public string Level { get; set; }
        public string Message { get; set; }

        public override Expression<Func<Log, bool>> ToExpression()
        {
            Expression<Func<Log, bool>> predicate = x => true;

            if (Ticket.HasValue)
                predicate = predicate.And(x => x.Ticket == Ticket);

            if (!string.IsNullOrWhiteSpace(Level))
                predicate = predicate.And(x => x.Level.StartsWith(Level));

            if (!string.IsNullOrWhiteSpace(Message))
                predicate = predicate.And(x => x.Message.StartsWith(Message));            

            return predicate;
        }
    }
}
